Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.Configuration
Imports System.Data
Imports System.Data.SqlClient

Public Partial Class TheatreStaff_InsertSessionTime
	Inherits System.Web.UI.Page
	Protected Sub Page_Load(sender As Object, e As EventArgs)
		srcgrdSession.SelectParameters("username").DefaultValue = Page.User.Identity.Name
		'srcgrdSchedule.SelectParameters["username"].DefaultValue = Page.User.Identity.Name;
		'grdSpecialTickets.Sort("MovieTitle", SortDirection.Ascending);
		Dim connectionString As String
		connectionString = WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString

		Dim con As New SqlConnection(connectionString)
		Dim cmd As New SqlCommand("SELECT TheatreId from TheatreStaff WHERE TheatreStaffUsername=@username", con)

		cmd.Parameters.AddWithValue("@username", Page.User.Identity.Name)

		Using con
			con.Open()
			Dim TheatreID As Object = cmd.ExecuteScalar()
			If TheatreID IsNot Nothing Then
				lblId.Text = TheatreID.ToString()
			End If
		End Using
		Dim con1 As New SqlConnection(connectionString)
		Dim cmd1 As New SqlCommand("SELECT Theatrename from Theatre WHERE Theatreid=@theatreid", con1)

		cmd1.Parameters.AddWithValue("@theatreid", lblId.Text)


		Using con1
			con1.Open()
			Dim Theatrename As Object = cmd1.ExecuteScalar()

			If Theatrename IsNot Nothing Then

				Label5.Text = Theatrename.ToString()
			End If
		End Using

    End Sub
    Private Sub Page_Load()
        If Not Page.IsPostBack Then
            'grdSession.SelectedIndex = 0;
            Label15.Text = String.Empty
        End If
        Label16.Text = String.Empty
    End Sub
    Protected Sub Cancel(ByVal sender As Object, ByVal e As EventArgs)

        txtSessionTimeI.Text = String.Empty
        ddlCinemaI.SelectedIndex = -1
        'txtDurationI.Text = string.Empty;
        Label15.Text = String.Empty
        Label16.Text = String.Empty
        'grdSession.DataBind();
    End Sub
    Protected Sub Clear(ByVal sender As Object, ByVal e As EventArgs)
        Label15.Text = String.Empty
        Label16.Text = String.Empty
    End Sub
    Protected Sub OnItemUpdated_Click(ByVal sender As Object, ByVal e As DetailsViewUpdatedEventArgs)
        'grdSession.DataBind();
        Label15.Text = String.Empty
        Label16.Text = String.Empty
    End Sub
    Protected Sub InsertS_Click(ByVal sender As Object, ByVal e As EventArgs)
        Label15.Text = String.Empty
        Label16.Text = String.Empty
        Dim connectionString As String
        connectionString = WebConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
        Dim con As New SqlConnection(connectionString)
        Dim con1 As New SqlConnection(connectionString)
        Dim cmd1 As New SqlCommand("INSERT session2(time,cinema) values (@time,@cinema)", con1)
        Dim cmd As New SqlCommand("SELECT time,cinema from session2,TheatreStaff,Cinema WHERE TheatreStaff.TheatreId=Cinema.TheatreId AND Cinema.CinemaId=session2.cinema AND Cinema.TheatreId=@TheatreId AND session2.time=@time AND session2.cinema=@cinema", con)
        Dim ParamString As String = lblId.Text
        Dim RowCount As Int32
        Dim HasS As [Boolean]

        cmd.Parameters.AddWithValue("@TheatreId", ParamString)
        cmd.Parameters.AddWithValue("@time", txtSessionTimeI.Text)
        cmd.Parameters.AddWithValue("@cinema", ddlCinemaI.SelectedValue)

        Using con
            con.Open()
            Dim Reader As SqlDataReader = cmd.ExecuteReader()

            If Reader.HasRows Then

                Label15.Text = "The session time" + " already exist in the database!"
                'lblCheck.Text = string.Empty;
                'ClientScript.RegisterClientScriptBlock(ClientScript.GetType(), "Focus", "<script language='JavaScript' 'showInsert();'/>");


                HasS = True
            Else

                HasS = False
            End If
        End Using
        Using con1
            con1.Open()
            If HasS = False Then

                cmd1.Parameters.AddWithValue("@time", txtSessionTimeI.Text)
                cmd1.Parameters.AddWithValue("@cinema", ddlCinemaI.SelectedValue)
                'cmd1.Parameters.AddWithValue("@Duration", txtDurationI.Text);
                RowCount = cmd1.ExecuteNonQuery()

                'txtDurationI.Text = string.Empty;
                'if (RowCount > 0)
                '{
                Label16.Text = "The session time " + txtSessionTimeI.Text.ToString() + " has been added sucessfully " + "to cinema " + ddlCinemaI.SelectedValue.ToString()
                'lblCorrect.Visible = true;
                txtSessionTimeI.Text = String.Empty

                '}
                ddlCinemaI.SelectedIndex = -1

            End If
        End Using
        'grdSession.DataBind();
    End Sub
End Class
